package com.yb.smart.plugin.data;

import com.yb.smart.api.SendDataHandle;
import com.yb.smart.plugin.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class SendDataHandleImpl implements SendDataHandle {

    @Override
    public String send(String productId, String mac, String deviceId, String serialno, String data) {
        System.out.println("SendDataHandleImpl send" + data);
        Map dataMap = JsonUtil.fromJson(data, Map.class);
        String  functionType = String.valueOf(dataMap.get("function_type"));
        String  identifier = String.valueOf(dataMap.get("identifier"));

        Map<String, String> map = new HashMap<>();
        map.put("function_type",functionType);
        map.put("identifier",identifier);
        map.put("mac",mac);
        map.put("serialno",serialno);
        map.put("data","success");
        return JsonUtil.toJson(map);
    }
}
